<template>
  <a-layout id="components-layout-demo-custom-trigger">
    <a-layout-sider :theme="theme" v-model="collapsed" :trigger="null" collapsible >
      <div class="logo">
        <img class="logoimg" src="../../assets/img/logo.png" alt="">
      </div>
      <a-menu
        :theme="theme"
        mode="inline"
        :default-selected-keys="[this.$route.path]"
        @click="
          (nav) => {
            this.$router.push(nav.key)
          }
        "
        >
        <a-menu-item v-for="(nav) in navs" :key="nav.path">
          <a-icon :type="nav.meta.icon" />
          <span>{{nav.name}}</span>
        </a-menu-item>
      </a-menu>
    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 0">
        <a-icon
          class="trigger"
          :type="collapsed ? 'menu-unfold' : 'menu-fold'"
          @click="() => (collapsed = !collapsed)"
        />
        <a-switch
          default-checked
          checked-children="dark"
          un-checked-children="light"
          @change="changeTheme"
        />
        <div
          :style="{ float: 'right', marginRight: '25px', cursor: 'pointer' }"
        >
          <a-dropdown placement="bottomLeft" arrow>
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:;">我的资料</a>
              </a-menu-item>
              <a-menu-item>
                <a href="javascript:;">消息中心</a>
              </a-menu-item>
              <a-menu-item @click="leave">
                <a href="javascript:;">退出登录</a>
              </a-menu-item>
            </a-menu>
            <div>
              <a-avatar
                src="https://img1.baidu.com/it/u=2045933031,585142074&fm=26&fmt=auto"
              />
              <span :style="{ marginLeft: '11px' }">等天晴</span>
            </div>
          </a-dropdown>
        </div>
      </a-layout-header>
      <a-layout-content
        :style="{ margin: '24px 16px', padding: '24px', background: '#fff', minHeight: '280px' }"
      >
      <!-- 内容 -->
        <router-view/>
      <!-- /内容出口 -->
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>
<script>
export default {
  data () {
    return {
      theme: 'dark',
      collapsed: false,
      navs: this.$router.options.routes[1].children.filter((nav) => nav.meta.isNav)
      /* role: JSON.parse(localStorage.getItem('userInfo')).role,
      navadmin: this.$router.options.routes[1].children.filter((nav) => nav.meta.isNav).filter((nav) => nav.meta.roles.includes(JSON.parse(localStorage.getItem('userInfo')).role)) */
    }
  },
  created () {
  },
  methods: {
    changeTheme (checked) {
      this.theme = checked ? 'dark' : 'light'
    },
    leave () {
      this.$confirm({
        title: '确认退出登录吗?',
        onOk: () => {
          localStorage.removeItem('token')
          localStorage.removeItem('userInfo')
          this.$router.go(0)
        },
        onNo () {}
      })
    }
  }
}
</script>
<style>
#components-layout-demo-custom-trigger .trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color 0.3s;
}

#components-layout-demo-custom-trigger .trigger:hover {
  color: #1890ff;
}

#components-layout-demo-custom-trigger .logo {
  height: 32px;
  background-color: transparent;
  margin: 16px;
  text-align: center;
}
.logo>.logoimg{
  width: 36px;
  height: 100%;
}
[v-cloak]{
  display: none;
}
</style>
